/*
 ------------------------------------------------------------------------------
 Copyright (C) 1996-2001 Id Software, Inc.

 This file is part of the Quake source code.

 The Quake source code is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or (at your
 option) any later version.

 The Quake source code is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 more details.

 You should have received a copy of the GNU General Public License along with
 the Quake source code; if not, write to the Free Software Foundation, Inc.,
 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 ------------------------------------------------------------------------------
*/


//
// sg_public.h - public header to all other files
//


#ifndef __SG_PUBLIC_H__
#define __SG_PUBLIC_H__


#define SGAME_API_VERSION			1

typedef struct glqSGame_t *	(*GETSGAMEAPI)(struct glqServer_t *);

// Functions exported by the game module
struct glqSGame_t {
	int						apiVersion;

	// Executes a string command for the given client.
	// The string has been tokenized by the engine and the command system
	// functions can be used to retrieve the command arguments.
	void					(*ClientCommand)(int clientNum);

	// Connects the given client to the game.
	// The user info string can be modified by the game.
	// Returns NULL if the client is allowed to connect, otherwise returns a
	// string with the reason for denial.
	const char *			(*ClientConnect)(int clientNum, bool localClient, const char *ip, char *userInfo, bool firstTime);

	// Disconnects the given client from the game
	void					(*ClientDisconnect)(int clientNum);

	// Spawns the player entity for the given client
	void					(*ClientBegin)(int clientNum);

	// Executes the user command for the given client
	void					(*ClientThink)(int clientNum, const userCmd_t *userCmd);

	// Writes a game state for the given client, starting at the given offset.
	// A game state usually contains things such as config strings and entity
	// baselines.
	// This is only called during the client connection process, before it is
	// allowed to enter the game.
	void					(*ClientWriteGameState)(int clientNum, msg_t *msg, int offset);

	// Writes a snapshot for the given client
	void					(*ClientWriteSnapshot)(int clientNum, msg_t *msg, int sequence, int deltaMessage, bool rateDelayed);

	// Sets the current ping for the given client
	void					(*ClientSetPing)(int clientNum, int ping);

	// Creates baselines for more efficient communications
	void					(*CreateBaselines)();

	// Runs a game frame
	void					(*RunFrame)();

	// Opportunity for the game to redraw debug tools and integrated editors
	void					(*Redraw)();

	// Initializes the game
	void					(*Init)(const char *levelName, int levelTime);

	// Shuts down the game
	void					(*Shutdown)();
};

// Functions imported from the engine
struct glqServer_t {
	glqCommon_t				glqCommon;
	glqMemory_t				glqMemory;
	glqFileSystem_t			glqFileSystem;
	glqCmdSystem_t			glqCmdSystem;
	glqCVarSystem_t			glqCVarSystem;
	glqMsgSystem_t			glqMsgSystem;
	glqDefManager_t			glqDefManager;
	glqParser_t				glqParser;
	glqSystem_t				glqSystem;
	glqTable_t				glqTable;
	glqCollision_t			glqCollision;
	glqRenderer_t			glqRenderer;
	glqSound_t				glqSound;
	glqGUI_t				glqGUI;

	// Sends a reliable command to the given client
	void					(*AddReliableCommand)(int clientNum, const char *fmt, ...);

	// Broadcasts a reliable command to all clients
	void					(*BroadcastReliableCommand)(const char *fmt, ...);

	// Drops the connection of the given client
	void					(*DropClient)(int clientNum, const char *reason);
};


#endif	// __SG_PUBLIC_H__